{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 导入饼图函数\n",
    "from pyecharts.charts import Pie"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "pie = Pie()",
   "id": "3ca61f891a1fb2af",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "# 准备数据  [['宝马',148],[],[]]\n",
    "from pyecharts.faker import Faker\n",
    "zip_obj = zip(Faker.cars, Faker.values())\n",
    "# zip_obj -> list\n",
    "# 遍历list\n",
    "result = []\n",
    "for item in list(zip_obj):\n",
    "   result.append(list(item))"
   ],
   "id": "1e026b2a06736453",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "# 添加数据\n",
    "from pyecharts import options as opts\n",
    "pie.add('',result)\n",
    "# 设置标题\n",
    "pie.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(\n",
    "        is_show=True,\n",
    "        title='汽车数量占比',\n",
    "        subtitle='不同类型的汽车',\n",
    "        pos_left='80',\n",
    "    )\n",
    ")\n",
    "pie.set_series_opts(label_opts=opts.LabelOpts(is_show=True,formatter=\"{b}--{c}\"))\n",
    "pie.render_notebook()"
   ],
   "id": "b7cd3e8a407ebc14",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "",
   "id": "7bd133b68193f5a3",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
